#!/bin/bash

# this is the build script for Natural Theme's patch
# requirement(s): Node.js

OUTPUT_DIR="./__output/patch"

# remove the output directory for a fresh copy
echo "removing __output directory . . ."
rm -rf ./__output

# create the output directory
echo "creating directory structure . . ."
mkdir -p $OUTPUT_DIR/tmp
mkdir -p $OUTPUT_DIR/js

echo "copying necessary files . . ."
cp ./patch.php $OUTPUT_DIR
cp -r ./inc $OUTPUT_DIR
cp -r ./css $OUTPUT_DIR
cp -r ./images $OUTPUT_DIR
cp -r ./js/vendor $OUTPUT_DIR/js

# copy these files to tmp directory for easy cleanup
cp -r ./less $OUTPUT_DIR/tmp
cp -r ./js $OUTPUT_DIR/tmp


# change directory
echo "changing working directory . . ."
cd $OUTPUT_DIR

# compile less files
echo "compiling less stylesheets . . ."
lessc tmp/less/patch.less > css/patch.css
lessc tmp/less/custom-styles.less > css/custom-styles.css

# minify javascripts using UglifyJS
echo "minifying js files . . ."
uglifyjs tmp/js/natext.js > js/natext.js
uglifyjs tmp/js/natext-smm-builder.js > js/natext-smm-builder.js
uglifyjs tmp/js/natext-page-builder.js > js/natext-page-builder.js
uglifyjs tmp/js/natext-bookshelf.js > js/natext-bookshelf.js
uglifyjs tmp/js/natext-bookshelf-Editor.js > js/natext-bookshelf-Editor.js
uglifyjs tmp/js/natext-bookshelf-Bookshelf.js > js/natext-bookshelf-Bookshelf.js

# have some cleanup task
echo "cleaning up . . ."

# remove all .svn folders
rm -rf `find . -name .svn`

# remove tmp directory
rm -rf tmp

echo "All Done..."
echo ""
echo "Reminder: set devil_mode to false"